package com.henu.engineer.service;

import com.henu.engineer.dao.entity.Teacher;
import com.henu.engineer.dao.entity.User;
import com.henu.engineer.dao.mapper.TeacherXmlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 包括普通教师，课程组负责人，专业负责人和院级负责人
 *
 * @author noexcept
 * @date 2021/7/26 7:36
 */
@Service
public class TeacherService {

    @Autowired
    TeacherXmlMapper teacherXmlMapper;

    /**
     * 新增老师
     * @param teacher
     * @param pwd
     * @return
     */
    public boolean insertTeacher(Teacher teacher, String pwd) {
        boolean result = false;
        try {
            result = teacherXmlMapper.insertTeacher(teacher);
            teacherXmlMapper.insertUser(new User(teacher.getId(), pwd, UserService.TEACHER));
        } catch (Exception e) {
            UserService.logger.error(e.getMessage());
        }
        return result;
    }

    /**
     * 更新联系方式
     * @param id
     * @param contact
     * @return
     */
    public boolean updateContact(String id,String contact){
        return teacherXmlMapper.updateContact(id, contact);
    }

    /**
     * 更新教师身份
     * @param rank 1=普通老师，2=课程组负责人，3=专业负责人，4=院级负责人
     * @return
     */
    public boolean updateRank(String id,Integer rank){
        String rankStr;
        switch (rank){
            case 1:rankStr = UserService.TEACHER;
            case 2:rankStr = UserService.COURSE_LEADER;
            case 3:rankStr = UserService.PROFESSIONAL_LEADER;
            case 4:rankStr = UserService.DEPART_LEADER;
            default:
                rankStr = UserService.TEACHER;
        }
        return teacherXmlMapper.updateRank(id,rankStr);
    }
}
